home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / dos / lock.c < prev    next >
C/C++ Source or Header  |  1996-09-12  |  3KB  |  112 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: lock.c,v 1.1 1996/09/11 12:54:46 digulla Exp $
  4.     $Log: lock.c,v $
  5.     Revision 1.1  1996/09/11 12:54:46  digulla
  6.     A couple of new DOS functions from M. Fleischer
  7.  
  8.     Desc:
  9.     Lang: english
  10. */
  11. #include <clib/exec_protos.h>
  12. #include <utility/tagitem.h>
  13. #include <dos/dosextens.h>
  14. #include <dos/filesystem.h>
  15. #include <clib/dos_protos.h>
  16. #include "dos_intern.h"
  17.  
  18. /*****************************************************************************
  19.  
  20.     NAME */
  21.     #include <clib/dos_protos.h>
  22.  
  23.     __AROS_LH2(BPTR, Lock,
  24.  
  25. /*  SYNOPSIS */
  26.     __AROS_LHA(STRPTR, name,       D1),
  27.     __AROS_LHA(LONG,   accessMode, D2),
  28.  
  29. /*  LOCATION */
  30.     struct DosLibrary *, DOSBase, 14, Dos)
  31.  
  32. /*  FUNCTION
  33.     Gets a lock on a file or directory. There may be more than one
  34.     shared lock on a file but only one if it is an exclusive one.
  35.     Locked files or directories may not be deleted.
  36.  
  37.     INPUTS
  38.     name       - NUL terminated name of the file or directory.
  39.     accessMode - One of SHARED_LOCK
  40.                 EXCLUSIVE_LOCK
  41.  
  42.     RESULT
  43.     Handle to the file or directory or 0 if the object couldn't be locked.
  44.     IoErr() gives additional information in that case.
  45.  
  46.     NOTES
  47.     The lock structure returned by this function is different
  48.     from that of AmigaOS (in fact it is identical to a filehandle).
  49.     Do not try to read any internal fields.
  50.  
  51.     EXAMPLE
  52.  
  53.     BUGS
  54.  
  55.     SEE ALSO
  56.  
  57.     INTERNALS
  58.  
  59.     HISTORY
  60.     29-10-95    digulla automatically created from
  61.                 dos_lib.fd and clib/dos_protos.h
  62.  
  63. *****************************************************************************/
  64.  
  65. {
  66.     __AROS_FUNC_INIT
  67.     __AROS_BASE_EXT_DECL(struct DosLibrary *,DOSBase)
  68.  
  69.     struct FileHandle *ret;
  70.  
  71.     /* Get pointer to process structure */
  72.     struct Process *me=(struct Process *)FindTask(NULL);
  73.  
  74.     /* Create filehandle */
  75.     ret=(struct FileHandle *)AllocDosObject(DOS_FILEHANDLE,NULL);
  76.     if(ret!=NULL)
  77.     {
  78.         /* Get pointer to I/O request. Use stackspace for now. */
  79.         struct IOFileSys io,*iofs=&io;
  80.  
  81.         /* Prepare I/O request. */
  82.         iofs->IOFS.io_Message.mn_Node.ln_Type=NT_REPLYMSG;
  83.         iofs->IOFS.io_Message.mn_ReplyPort   =&me->pr_MsgPort;
  84.         iofs->IOFS.io_Message.mn_Length      =sizeof(struct IOFileSys);
  85.         iofs->IOFS.io_Flags=0;
  86.         iofs->IOFS.io_Command=FSA_OPEN;
  87.         /* io_Args[0] is the name which is set by DoName(). */
  88.         switch(accessMode)
  89.         {
  90.             case EXCLUSIVE_LOCK:
  91.                 iofs->io_Args[1]=FMF_LOCK|FMF_READ;
  92.                 break;
  93.             case SHARED_LOCK:
  94.                 iofs->io_Args[1]=FMF_READ;
  95.                 break;
  96.             default:
  97.                 iofs->io_Args[1]=accessMode;
  98.                 break;
  99.         }
  100.         if(!DoName(iofs,name))
  101.         {
  102.             ret->fh_Device=iofs->IOFS.io_Device;
  103.             ret->fh_Unit  =iofs->IOFS.io_Unit;
  104.             return MKBADDR(ret);
  105.         }
  106.         FreeDosObject(DOS_FILEHANDLE,ret);
  107.     }else
  108.     me->pr_Result2=ERROR_NO_FREE_STORE;
  109.     return 0;
  110.     __AROS_FUNC_EXIT
  111. } /* Lock */
  112.